Add option to show docstrings in which-key buffer
authorJustin Burkett <justin@burkett.cc>
Wed, 31 Jan 2018 01:29:51 +0000 (20:29 -0500)
committerJustin Burkett <justin@burkett.cc>
Wed, 31 Jan 2018 01:29:51 +0000 (20:29 -0500)
Implements a simple version of the suggestion in #185

which-key.el

index 3400491b8676dbb717b00153c1b8e3119e5a74e3..6ae8b725f82c7bc19309408a0fe48113a55a2a4b 100644 (file)
@@ -215,6 +215,15 @@ only the first match is used to perform replacements from
   :group 'which-key
   :type 'boolean)
 
+(defcustom which-key-show-docstrings nil
+  "If non-nil, show each command's docstring next to the command
+in the which-key buffer. This will only display the docstring up
+to the first line break. You probably also want to adjust
+`which-key-max-description-length' at the same time if you use
+this feature."
+  :group 'which-key
+  :type 'boolean)
+
 (defcustom which-key-highlighted-command-list '()
   "A list of strings and/or cons cells used to highlight certain
 commands. If the element is a string, assume it is a regexp
@@ -1584,14 +1593,24 @@ alists. Returns a list (key separator description)."
              (local (eq (which-key--safe-lookup-key local-map (kbd keys))
                         (intern orig-desc)))
              (hl-face (which-key--highlight-face orig-desc))
-             (key-binding (which-key--maybe-replace (cons keys orig-desc))))
+             (key-binding (which-key--maybe-replace (cons keys orig-desc)))
+             (final-desc (which-key--propertize-description
+                          (cdr key-binding) group local hl-face orig-desc)))
+        (when (and which-key-show-docstrings
+                   (commandp (intern orig-desc))
+                   (documentation (intern orig-desc)))
+          (setq final-desc
+                (format "%s %s"
+                        final-desc
+                        (car
+                         (split-string
+                          (documentation (intern orig-desc)) "\n")))))
         (when (consp key-binding)
           (push
            (list (which-key--propertize-key
                   (which-key--extract-key (car key-binding)))
                  sep-w-face
-                 (which-key--propertize-description
-                  (cdr key-binding) group local hl-face orig-desc))
+                 final-desc)
            new-list))))
     (nreverse new-list)))